package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.ScenicInfo;
import com.ruoyi.system.mapper.ScenicInfoDao;
import com.ruoyi.system.service.ScenicInfoService;
import org.springframework.stereotype.Service;

/**
 * Auto created by codeAppend plugin
 */
@Service
public class ScenicInfoServiceImpl extends ServiceImpl<ScenicInfoDao, ScenicInfo> implements ScenicInfoService {
    @Override
    public int insertScenicInfo(ScenicInfo scenicInfo) {
        ScenicInfo si = new ScenicInfo();
        si.setName(scenicInfo.getName());
        si.setImageInfo(scenicInfo.getImageInfo());
        si.setIntroduce(scenicInfo.getIntroduce());
        si.setTag(scenicInfo.getTag());
        si.setAddress(scenicInfo.getAddress());
        return baseMapper.insert(si);
    }

    @Override
    public int updateScenicInfo(ScenicInfo scenicInfo) {
        LambdaQueryWrapper<ScenicInfo> lqw =new LambdaQueryWrapper<>();
        lqw.eq(ScenicInfo::getId,scenicInfo.getId());
        ScenicInfo si = baseMapper.selectOne(lqw);
        if (si == null){
            throw new RuntimeException("ScenicInfo not found");
        }
        si.setName(scenicInfo.getName());
        si.setImageInfo(scenicInfo.getImageInfo());
        si.setIntroduce(scenicInfo.getIntroduce());
        si.setTag(scenicInfo.getTag());
        si.setAddress(scenicInfo.getAddress());
        return baseMapper.updateById(si);
    }

    @Override
    public int deleteScenicInfoById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public ScenicInfo selectScenicInfoById(Long id) {
        return baseMapper.selectById(id);
    }

    // use "baseMapper" to call jdbc
    // example: baseMapper.insert(entity);
    // example: baseMapper.selectByPage(params);

}
